package com.tz.yiqingapp.controller.common;

import com.tz.yiqingapp.bean.Spiderlog;
import com.tz.yiqingapp.mapper.SpiderMapper;
import com.tz.yiqingapp.services.dao.CommandServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.junit.platform.commons.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.logging.Logger;


@Component
@Slf4j
public class GetSpiderLogTask {

    @Autowired
    CommandServiceImpl commandService;

    @Autowired
    SpiderMapper spiderMapper;

    @Scheduled(fixedRate = 1000000)
    public void execute() {
        String res = commandService.executeCmd("cd spider/server ;node spider.js");
        System.out.println(res);
        Spiderlog spiderlog = new Spiderlog();
        spiderlog.setCreatetime(LocalDateTime.now());
        spiderlog.setData(res);
        spiderMapper.insert(spiderlog);
    }


}
